﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<%@ Import Namespace="volva.Models" %>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <%
        Station station = ViewData["station"] as Station;
         %>

    <h2><a href="/Station/Details/<% Response.Write(station.id); %>">Dagskrá fyrir <% Response.Write(station.name); %></a></h2>
    
    <% 
        List<ScheduleItem> schedule = ViewData["schedule"] as List<ScheduleItem>;
        /*List<int> hours = new List<int>();
        
        for(int i = 0; i < 95; i++)
	    {
            DateTime time = Convert.ToDateTime(schedule[i].airDateTime);
            if (time.Minute == 00)
            {
                hours.Add(time.Hour);
            }
	    }*/
        %>
        
        
            <div id="currentSchedule" class="half clearfix">
            <table>
                <tr>
                    <th class="">&nbsp;</th>
                    <th class="">Dagsskrárliður</th>
                </tr>
            <!-- div>00:00</div> <div>01:00</div> <div>02:00</div>
            <div>03:00</div> <div>04:00</div> <div>05:00</div>
            <div>06:00</div> <div>07:00</div> <div>08:00</div>
            <div>09:00</div> <div>10:00</div> <div>11:00</div>
            <div>12:00</div> <div>13:00</div> <div>14:00</div>
            <div>15:00</div> <div>16:00</div> <div>17:00</div>
            <div>18:00</div> <div>19:00</div> <div>20:00</div>
            <div>21:00</div> <div>22:00</div> <div>23:00</div>
            <div>00:00</div>
            </div -->
        
        <%  
            for (int j = 0; j < 24; j++)
        { 
            List<ScheduleItem> showsOnTheHour = schedule.FindAll(
                    n => n.airDateTime.HasValue && 
                    n.airDateTime.Value.Hour == j &&
                    n.Video != null)
                .OrderBy(n => n.airDateTime.Value.Minute).ToList();

            //Response.Write(hours[j].ToString("00") + ":00 - ");
            Response.Write("<tr>");
            Response.Write("<td>" + j.ToString("00") + ":00</td><td>");
            foreach (ScheduleItem si in showsOnTheHour)
            {
                if (si.airDateTime.Value.Hour == j)
                {
                    Response.Write("<a href='/Home/Watch/" + si.Video.id + "'>" + si.Video.name + "</a><br />");
                }
                    
            }
            Response.Write("</td></tr>");
        }
        %>
            </table>
        </div>
        <div id="related" class="half">
        <table>
            <tr>
                <th>Þáttur</th>
                <th>Tími</th>
                <th>Eyða</th>
            </tr>
            
            <%

                List<Video> reccomentations = ViewData["reccomendation"] as List<Video>;
                foreach (Video v in reccomentations)
                {
                    %>
                    
                    <tr class="suggestion">
                    <td><%Response.Write(v.name);%></td>
                    <td>
                    
                        <form action="/Station/ChangeSchedule/<%= (station.id) %>"  method="post">
                        <input type="hidden" name="deleteVideo" value="false" />
                        <input type="hidden" name="videoId" value="<%= (v.id) %>" />
                        <input type="submit" value="Bæta við" class="btn add" />
                        </form>
                     </td>
                     
                     <td>
                      <form action="/Station/ChangeSchedule/<%= (station.id) %>"  method="post">
                        <input type="hidden" name="deleteVideo" value="true" />
                        <input type="hidden" name="videoId" value="<%= (v.id) %>" />
                        <input type="submit" value="X" class="btn" />
                      </form>
                     </td>
                    </tr>
                    
                    <%
                }
                 %>      
        </table>
        </div>
        
                    <%
            reccomentations = ViewData["reccomendation"] as List<Video>;
            Response.Write("<script type='text/javascript'>\r\n");
            Response.Write("times = new Array(24);\r\n");
            for (int i = 0; i < 24; i++)
            {
                Response.Write("times[" + i + "] = new Array(4);\r\n");
                for (int j = 0; j < 4; j++)
                {
                    int min = j * 15;
                    List<ScheduleItem> showsOnThisTime = (from s in schedule
                                                          where s.airDateTime.Value.Hour == i &&
                                                          s.airDateTime.Value.Minute == min && 
                                                          s.Video != null
                                                          select s).ToList();

                    if (showsOnThisTime.Count <= 0)
                    {
                        Response.Write("times[" + i + "][" + min + "] = true;\r\n");
                    }
                    else
                    {
                        Response.Write("times[" + i + "][" + min + "] = false;\r\n");
                    }
                }                
            }
            Response.Write("scheduleTimeThings();");
            Response.Write("</script>");
                %>

</asp:Content>
